// export default {
//     throttle: function (fn, delay=2000) {
//         var timer = null;
//         return function () {
//             var context = this,
//                 args = arguments;
//             if (timer === null) {
//                 timer = setTimeout(function () {
//                     fn.apply(context, args);
//                     timer = null;
//                 }, delay);
//             }
//         }
//     }
// }
// throttle.js
function throttle(fn, delay = 2000) {
  let timer = null;
  return function () {
    if (!timer) {
      timer = setTimeout(() => {
        fn.apply(this, arguments);
        timer = null;
      }, delay);
    }
  }
}

export default {
  mounted(el, binding) {
    const debouncedFn = throttle(binding.value, binding.arg || 2000);
    el.addEventListener('click', debouncedFn);
  }
}
